﻿using System.Collections.Generic;
using Entitas;
class EnemyFlipSpriteSystem : ReactiveSystem<EnemyEntity>
{
    public EnemyFlipSpriteSystem(Contexts contexts) : base(contexts.enemy)
    {

    }

    protected override void Execute(List<EnemyEntity> entities)
    {
        foreach (var e in entities)
        {
            switch (e.direction.value)
            {
                case Direction.Up_Left:
                    e.ReplaceSpriteFlip(true, e.spriteFlip.FlipY);
                    break;
                case Direction.Up_Right:
                    e.ReplaceSpriteFlip(false, e.spriteFlip.FlipY);
                    break;
                case Direction.Down_Left:
                    e.ReplaceSpriteFlip(true, e.spriteFlip.FlipY);
                    break;
                case Direction.Down_Right:
                    e.ReplaceSpriteFlip(false, e.spriteFlip.FlipY);
                    break;
                case Direction.Left:
                    e.ReplaceSpriteFlip(true, e.spriteFlip.FlipY);
                    break;
                case Direction.Right:
                    e.ReplaceSpriteFlip(false, e.spriteFlip.FlipY);
                    break;
                default:
                    break;

            }
        }
    }

    protected override bool Filter(EnemyEntity entity)
    {
        return entity.hasDirection && entity.hasSpriteFlip;
    }

    protected override ICollector<EnemyEntity> GetTrigger(IContext<EnemyEntity> context)
    {
        return context.CreateCollector(EnemyMatcher.Direction.AddedOrRemoved());
    }
}
